#include "stdafx.h"
#include "date.h"
#include "employees.h"
#include <cstring>
#include <iostream>
using namespace std;


//class Employee implementation
unsigned Employee::empCounter = 0;

void Employee::allocDynamicDataName(const char* name)
{
    this->name = new char[sizeof(name) + 1];
}

void Employee::allocDynamicDataDepartmentName(const char* departmentName)
{
    this->departmentName = new char[sizeof(name) + 1];
}


void Employee::removeDynamicDataName()
{
    delete this->name;
}

void Employee::removeDynamicDataDepartmentName()
{
    delete this->departmentName;
}

Employee::Employee(const char* const tname, const Date date, const char* const tdepartmentName, const double salary)
{
	this->name = new char[strlen(tname) + 1];
	strcpy_s(this->name,(strlen(name)+1),tname);
	this->departmentName = new char[strlen(tdepartmentName) + 1];
    strcpy_s(this->departmentName,(strlen(departmentName)+1),tdepartmentName);
    
	this->hireDate = date;
    this->salary = salary;
    empCounter++;
    cout << "empCounter: " << empCounter << endl;

}

Employee::Employee(const Employee& emp)
{
    allocDynamicDataName(emp.name);
    allocDynamicDataDepartmentName(emp.departmentName);

    strcpy_s(this->name,(strlen(emp.name)+1),emp.name);
	strcpy_s(this->departmentName,(strlen(emp.departmentName)+1),emp.departmentName);
    this->hireDate = emp.hireDate;
    this->salary = emp.salary;
    empCounter++;
    cout << "empCounter: " << empCounter << endl;
}

Employee& Employee::operator = (const Employee& emp)
{
    strcpy_s(this->name,(strlen(emp.name)+1),emp.name);
    strcpy_s(this->departmentName,(strlen(emp.departmentName)+1),emp.departmentName);
    this->hireDate = emp.hireDate;
    this->salary = emp.salary;
	return *this;
}

Employee::~Employee()
{
    removeDynamicDataName();
    removeDynamicDataDepartmentName();
    empCounter--;
    cout << "empCounter: " << empCounter << endl;
}


void Employee::setEmployeeName(const char* name)
{
    allocDynamicDataName(name);
    strcpy_s(this->name,(strlen(name)+1),name);
}

void Employee::setEmployeeHireDate(const unsigned year,const unsigned month, const unsigned day)
{
    this->hireDate.setDate(year,month,day);
}

void Employee::setEmployeeDepartmentName(const char* dptName)
{
    allocDynamicDataDepartmentName(dptName);
    strcpy_s(this->departmentName,(strlen(dptName)+1),dptName);
}

void Employee::setEmployeeSalary(const double salary)
{
    this->salary = salary;
}

char* Employee::getEmployeeName() const
{
    return this->name;
}

Date Employee::getEmployeeHireDate() const
{
    return hireDate;
}

char* Employee::getEmployeeDepartmentName() const
{
    return this->departmentName;
}

double Employee::getEmployeeSalary() const
{
    return this->salary;
}

void Employee::printEmployee() const
{
    unsigned year = this->hireDate.getDateYear();
    unsigned month = this->hireDate.getDateMonth();
    unsigned day = this->hireDate.getDateDay();
    cout << this->name << endl << year << " " << month << " " << day << endl << this->departmentName << endl << this->salary << endl;
}